<template>
  <t-dialog :header="header" :confirmBtn="null" :visible.sync="visible" :onClose="closeDialog"
            :closeOnOverlayClick="false"
            width="80%" top="5%">
    <div style="height: 65vh">
      <t-table row-key="approveId" :columns="columns" :data="data"
               :loading="dataLoading">
         <template #projectName="{ row }">
            <t-link  @click="handleByAllDetails(row)" hover="color" theme="primary">{{row.projectName}}</t-link>
          </template>
          <template #[`subjectClassification`]="{row}">
            {{ row.subjectClassification | filterByDict(standardSystemTree) }}
          </template>
           <template #standardProperty="{ row }">
        {{ row.standardProperty | filterByDict(dict.type.standard_property) }}
      </template>

        <template #formulateType="{ row }">
         {{ row.formulateType | filterByDict(dict.type.formulate_type) }} <span v-if="row.formulateType!=='1'">({{ row.reviseNum }})</span>
        </template>

        <template #draftUnitNames="{ row }">
        <t-tooltip :content="row.draftUnitNames">
          <p style="display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; text-overflow: ellipsis; overflow: hidden;">
            {{row.draftUnitNames || "-"}}
          </p>
        </t-tooltip>
      </template>

        <template #projectUp="{ row }">
        {{ row.projectUp === '1'?'是':'否' }}
      </template>
      <template #patentUp="{ row }">
        {{ row.patentUp === '1'?'是':'否' }}
      </template>
      <template #xsReviewStatus="{ row }">
            <t-tag v-if="row.xsReviewStatus" @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.open_approve_list=true" class="cursor-pointer" :theme="handleTheme(row.xsReviewStatus, dict.type.xs_review_status)" variant="light">
              {{ row.xsReviewStatus | filterByDict(dict.type.xs_review_status) }}
            </t-tag>
            <t-tag  class="cursor-pointer" v-else @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.open_approve_list=true" theme="warning" variant="light">未评审</t-tag>
          </template>
         <template #standardStatus="{ row }">
        <t-tag   @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.open_approve_list=true"   class="cursor-pointer" :theme="handleTheme(row.standardStatus, dict.type.standard_status)" variant="light">
          {{ row.standardStatus | filterByDict(dict.type.standard_status) }}
        </t-tag>
      </template>
      </t-table>
       <standardDetailDialog :tabDefaultValue="tabDefaultValue" :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_standard_detail" v-if="dialog.open_standard_detail">
    </standardDetailDialog>
      <approve-list :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_approve_list"
                    v-if="dialog.open_approve_list"></approve-list>
                    
    </div>
  </t-dialog>
</template>

<script>
import ApproveList from "./approve-list.vue";
import standardDetailDialog from "@/pages/bzh/standard/components/standard-detail-dialog.vue";

export default {
  name: "show-approver-project",
  dicts: ["standard_property","formulate_type","standard_status","xs_review_status"],
  components: {
    ApproveList,
    standardDetailDialog
  },
  props: ["userId","header","cType"],
  data() {
    return {
      visible: true,
      dataLoading: false,
      standardSystemTree:undefined,
      tabDefaultValue:"",
      data: [],
      dialog: {
        header: "",
        objId: 0,
        open_approve_list: false,
        open_standard_detail:false
      },
      columns:[
        {
          colKey: "projectName",
          title: "标准名称",
          align: "center",
          width: 220
        },
        {
          colKey: "standardProperty",
          title: "标准性质",
          align: "center",
        },
        {
          colKey: "formulateType",
          title: "制定/修订",
          align: "center",
          width: 100
        },
        {
          colKey: "manageDeptName",
          title: "主管部门",
          align: "center",
          width: 180,
        },
        {
          colKey: "draftUnitNames",
          title: "起草单位",
          align: "center",
          width: 180,
        },
        {
          colKey: "subjectClassification",
          title: "学科分类",
          align: "center",
          width: 100
        },
        {
          colKey: "completeDate",
          title: "计划完成时间",
          align: "center",
          width: 130,
          sorter: true,
        },
        {
          colKey: "projectUp",
          title: "有项目支撑",
          align: "center",
          width: 100
        },
        {
          colKey: "patentUp",
          title: "有涉及专利",
          align: "center",
          width: 100
        },
        {
          colKey: "createTime",
          title: "创建时间",
          align: "center",
          width: 200
        },
        {
          colKey: "standardStatus",
          title: "标准状态",
          align: "center",
          width: 160,
          fixed: 'right'
        },
        {
          colKey: "xsReviewStatus",
          title: "标委会审批状态 ",
          align: "center",
          width: 160,
          fixed: 'right'
        },
      ],
    }
  },
  created() {
    this.getList()
    this.getStandardSystemTree()
  },
  methods: {
    getList() {
      this.dataLoading = true;
      this.$api.bzh.approve.getApproverReviewByUserId(this.userId,this.cType).then((res) => {
        this.data = res.data;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false
        this.$message.error(e.toString());
      });
    },
    getStandardSystemTree() {
      this.$api.bzh.standard.standardSystemTree().then(res => {
        this.standardSystemTree =res.data
      }).catch(e => {
        this.$message.error(e.toString());
      })
    },
    handleByAllDetails(row){
      const xsReviewType  = Number(this.cType)
      switch (xsReviewType) {  
      case 1:  
        this.tabDefaultValue = "2"
        break;  
      case 2: 
        this.tabDefaultValue = "4"
        break;  
      case 3:  
        this.tabDefaultValue = "5"
        break;  
      default:  
        this.tabDefaultValue = "2"
      }
      this.dialog.objId=row.id
      this.dialog.header=row.projectName
      this.dialog.open_standard_detail=true
    },
    closeDialog() {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style scoped>

</style>
